package com.zdp.degisn.pipe_filter;

import com.zdp.degisn.pipe_filter.entity.Context;
import com.zdp.degisn.pipe_filter.filter.AbstarctFilterChain;
import com.zdp.degisn.pipe_filter.filter.Filter;
import com.zdp.degisn.pipe_filter.filter.FilterChain;

import java.util.Objects;

/**
 * @author zhengdp
 * @Description 整合出一个完整的责任链
 * @Date 2022/8/28 18:06
 * @Created by zhengdp
 */
public class FilterPipe {

    private FilterChain first;

    // 入口
    public void process(Context context){
        if(Objects.nonNull(first)){
            first.handle(context);
        }
    }

    // 前插
    public FilterPipe addFirst(Filter filter){
        first = new AbstarctFilterChain(first,filter);
        // 链式调用
        return this;
    }



}
